一、流程分析
二、代码
1.view层
(1)desc.jsp
2.servlet层
(1)OrderServlet.java
1 /** 2 * 确认订单 3 * @param req 4 * @param resp 5 * @return 6 * @throws ServletException 7 * @throws IOException 8 */ 9 public String confirm(HttpServletRequest req, HttpServletResponse resp)10 throws ServletException, IOException {11 String id = req.getParameter("oid");12 int status = service.findStatus(id);13 14 if(status != 3) {15 req.setAttribute("code", "error");16 req.setAttribute("msg", "态不对,不能确认收货!");17 return "f:/jsps/msg.jsp";18 }19 service.updateStatus(id, 4);20 req.setAttribute("code", "success");21 req.setAttribute("msg", "恭喜,交易成功!");22 return "f:/jsps/msg.jsp"; 23 }24 25 /**26 * 取消收货27 * @param req28 * @param resp29 * @return30 * @throws ServletException31 * @throws IOException32 */33 public String cancel(HttpServletRequest req, HttpServletResponse resp)34 throws ServletException, IOException {35 String id = req.getParameter("oid");36 int status = service.findStatus(id);37 38 if(status != 1) {39 req.setAttribute("code", "error");40 req.setAttribute("msg", "状态不对,不能取消!");41 return "f:/jsps/msg.jsp";42 }43 service.updateStatus(id, 5);44 req.setAttribute("code", "success");45 req.setAttribute("msg", "您的订单已取消!");46 return "f:/jsps/msg.jsp"; 47 }
3.service层
(1)OrderService.java
1 /** 2 * 修改订单状态 3 * @param id 4 * @param status 5 */ 6 public void updateStatus(String id, int status) { 7 try { 8 dao.updateStatus(id, status); 9 } catch (SQLException e) {10 throw new RuntimeException(e);11 }12 }13 14 /**15 * 查找订单状态16 * @param id17 * @return18 */19 public int findStatus(String id) {20 try {21 return dao.findStatus(id);22 } catch (SQLException e) {23 throw new RuntimeException(e);24 }25 }
4.dao层
(1)OrderDao.java
1 /** 2 * 修改订单状态 3 * @param id 4 * @param status 5 * @throws SQLException 6 */ 7 public void updateStatus(String id, int status) throws SQLException { 8 String sql = "update t_order set status=? where oid=?"; 9 qr.update(sql, status, id);10 }11 12 /**13 * 查找订单状态14 * @param id15 * @return16 * @throws SQLException17 */18 public int findStatus(String id) throws SQLException {19 String sql = "select status from t_order where oid=?";20 Number status = (Number) qr.query(sql, new ScalarHandler(), id);21 return status.intValue();22 }